package org.dromara.xyyw.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.xyyw.domain.bo.XyywShopProductCommentLikeBo;
import org.dromara.xyyw.domain.query.XyywShopProductCommentLikeQuery;
import org.dromara.xyyw.domain.vo.XyywShopProductCommentLikeVo;
import org.dromara.xyyw.service.IXyywShopProductCommentLikeService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 讨论点赞
 *
 * @author yf
 * @date 2024-05-29
 */
@Validated
@RestController
@RequestMapping("/xyyw/shopProductCommentLike")
public class XyywShopProductCommentLikeController extends BaseController {

    @Autowired
    private IXyywShopProductCommentLikeService xyywShopProductCommentLikeService;

    /**
     * 查询讨论点赞列表
     */
    @SaCheckPermission("xyyw:shopProductCommentLike:list")
    @GetMapping("/list")
    public TableDataInfo<XyywShopProductCommentLikeVo> list(XyywShopProductCommentLikeQuery query) {
        return xyywShopProductCommentLikeService.queryPageList(query);
    }

    /**
     * 导出讨论点赞列表
     */
    @SaCheckPermission("xyyw:shopProductCommentLike:export")
    @Log(title = "讨论点赞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XyywShopProductCommentLikeQuery query, HttpServletResponse response) {
        List<XyywShopProductCommentLikeVo> list = xyywShopProductCommentLikeService.queryList(query);
        ExcelUtil.exportExcel(list, "讨论点赞", XyywShopProductCommentLikeVo.class, response);
    }

    /**
     * 获取讨论点赞详细信息
     *
     * @param discussionLikeId 主键
     */
    @SaCheckPermission(value = {"xyyw:shopProductCommentLike:query", "xyyw:shopProductCommentLike:edit"}, mode = SaMode.OR)
    @GetMapping("/{discussionLikeId}")
    public R<XyywShopProductCommentLikeVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Integer discussionLikeId) {
        return R.ok(xyywShopProductCommentLikeService.queryById(discussionLikeId));
    }

    /**
     * 新增讨论点赞
     */
    @SaCheckPermission("xyyw:shopProductCommentLike:add")
    @Log(title = "讨论点赞", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XyywShopProductCommentLikeBo bo) {
        return toAjax(xyywShopProductCommentLikeService.insertByBo(bo));
    }

    /**
     * 修改讨论点赞
     */
    @SaCheckPermission("xyyw:shopProductCommentLike:edit")
    @Log(title = "讨论点赞", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XyywShopProductCommentLikeBo bo) {
        return toAjax(xyywShopProductCommentLikeService.updateByBo(bo));
    }

    /**
     * 删除讨论点赞
     *
     * @param discussionLikeIds 主键串
     */
    @SaCheckPermission("xyyw:shopProductCommentLike:remove")
    @Log(title = "讨论点赞", businessType = BusinessType.DELETE)
    @DeleteMapping("/{discussionLikeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Integer[] discussionLikeIds) {
        return toAjax(xyywShopProductCommentLikeService.deleteWithValidByIds(List.of(discussionLikeIds)));
    }
}
